<?php
namespace app\plus_exam\model;
use think\Model;

/**
 *  题库类型
 * Class Category
 * @package app\exam\model
 */
class Category extends Model{

    protected $pk     = 'id';
    protected $table  = 'sp_plus_exam_category';
    protected $autoWriteTimestamp = true;
    protected $pageNumber = 20;

    /**
     * 单个
     * @param int $param
     * @return array
     */
    public function find_info($param) {
        return self::get($param);
    }

    /**
     * 列表
     * @access public
     * @param array $where
     */
    public function select_lists(){    
        return $this->order('id desc')->paginate($this->pageNumber);
    }

    /**
     * 列表
     * @access public
     * @param array $where
     */
    public function select_nopage_lists(){    
        return $this->order('id desc')->select();
    }
  
    /**
     * 添加
     * @param array $param
     * @return int
     */
    public function add_data($param) {
        $data = [
            'name' => $param['name'],
            'create_time' => time(),
            'update_time' => time(),
        ];
        return $this->insertGetId($data);
    }
    
    /**
     * 编辑
     * @param type $param
     */
    public function edit_data($param) {
        $data = [
            'name'=> $param['name'],
            'update_time' => time(),
        ];
        $where = ['id'=>$param['id']];
        return $this->where($where)->update($data);
    }
    
    /**
     * 删除数据
     * @param int $id
     */
    public function delete_data($id) {
        return $this->destroy($id);
    }
}